<?php require_once(dirname(__FILE__)."/config/config.php"); ?>
  <?php include (dirname(__FILE__)."/include/header.php"); ?>
<!DOCTYPE html>
<html lang="zh">
<head>
<title>点一下,宁波最大的外卖订餐网站!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="外卖,网上订餐,餐厅,美食" />
<meta name="description" content="查看附近的餐厅、美食信息" />
<meta http-equiv="X-UA-Compatible" content="chrome=IE6">
<script type="text/javascript" src="<?php echo SITE_ROOT;?>/js/jquery-1.8.0.js"></script>
<script type="text/javascript" src="<?php echo SITE_ROOT;?>/js/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<?php  
if($_SESSION['_cart']['food']=="")
{

	echo "<script>location.href='cart_empty.php';</script>";
}
$a=totalPrice();
// echo $a;
if($a<=0){
 echo "<script>location.href='cart_empty.php';</script>";
}

?>
<?php 
	if(!empty($_POST['submit'])){
		$mail=$_POST['mail'];
		$password=$_POST['password'];
		$sql="SELECT a.user_id,a.username,a.password,a.mail,a.integral,a.shop_id,a.remark,a.is_delete AS user_is_delete ,a.create_user AS user_create_user ,a.create_time AS user_create_time,a.update_user AS user_update_user,a.update_time AS user_update_time ,b.*  FROM zy_user a LEFT JOIN zy_shop b ON a.shop_id=b.shop_id WHERE a.`mail`='".$mail."' AND PASSWORD='".$password."' LIMIT 0,1";
		$result = mysql_query($sql);
		if($rs = mysql_fetch_array($result)){              
				if($rs['shop_id']==0){          
				$_SESSION['_user']=$rs;
			 echo "<script>location.href='check_out.php';</script>";
				unset($_SESSION['_shop']);
				}
		}else{                        //如果没有这个用户
			$error="Email或密码错误!";
		}
	}
	?>
<div id="background"></div>
<div class="full-content-wrapper">
  <div class="cart-container">
    <div class="row cart-wrapper">
      <div class="span9 cart-header">
        <div class="cart-nav">
          <ul>
            <!--此处留空-->
           <!--  <li><a href="<?php echo SITE_ROOT;?>">返回点一下</a></li> -->
           <!-- <li><a href="<?php echo SITE_ROOT;?>/user/order_list.php?method=one-month">点单中心</a></li> -->
          </ul>
        </div>
      </div>
      <div class="span9 flow">
        <ul>
          <li>1、选择美食 →</li>
          <li class="current">2、填写核对点单信息 →</li>
          <li class="last">3、成功提交点单</li>
        </ul>
      </div>
      <div class="span9 main-box bordered-box">
        <h2>我的美食篮子<a href="<?php echo SITE_ROOT?>/index_shop.php?shop_id=<?php echo $_SESSION['_cart']['shop_id'];?>" target="_blank">@<?php echo $_SESSION['_cart']['shop_name'];?></a></h2>
		<?php 
		$sql="select * from zy_shop where shop_id =".$_SESSION['_cart']['shop_id'];
		//echo $sql;
		$result=mysql_query($sql);
		$zy_shop=mysql_fetch_array($result);?>
        <div class="row">
          <div class="span9">
            <div class="item-tables">
              <table class="table cart-detail-table" id="cart-detail-table-1">
                <thead>
                  <tr class="">
                    <th class="name">美食篮子</th>
                    <th class="price">单价</th>
                    <th class="quantity">共<strong id="total_quantity"><?php echo outputCartTotals();?></strong>份</th>
                    <th class="subtotal" id="subtotal">总计<strong id="total_price"><?php echo totalPrice()+$zy_shop['surcharge'];?></strong>元</th>
                    <th class="action"><a href="index_shop.php?method=clear&shop_id=<?php echo $_SESSION['_cart']['shop_id'];?>">清空</a></th>
                  </tr>
                </thead>
               <tbody id="cart-details">
                <?php echo outputAllCartDetails(); ?>
                </tbody>
              </table>
            </div>
            <div class="summary">
               <div class="text"><?php echo outputCartTotal();?></div>
            </div>
          </div>
        </div>
        <h2>确认您的送餐地址</h2>
        <?php if(isset($_SESSION['_user'])){
	        $res=mysql_query("select * from zy_address where is_default=1 and is_delete=0 and user_id=".$_SESSION['_user']['user_id']);
	        $result=mysql_fetch_array($res);
        }
	     ?>
        <div class="row">
          <div class="span4 address-form">
            <form action="" name="form1" method="post" id="checkout-form" class="form-horizontal" onSubmit="return clickme();">
              <fieldset>
                <div class="address-row control-group">
                  <label class="control-label" for="address"><span class="required-mark">*</span>详细地址：</label>
                  <div class="controls">
                    <input class="span3" id="address" name="address" size="30" type="text" value="<?php echo $result['address']?>" />
                    <p class="help-block">(请填详细一点)</p>
                  </div>
                </div>
                <!-- /control-group -->
                <div class="phone-row control-group">
                  <label for="phone" class="control-label"><span class="required-mark">*</span>联系电话：</label>
                  <div class="controls">
                    <input class="span3" id="phone" name="phone" size="30" type="text" value="<?php echo $result['phone'];?>" />
                    <span class="help-block">(外卖到时将以该电话通知您)</span> </div>
                </div>
                <!-- /control-group -->
                <div class="phone-bk-row control-group">
                  <label for="bak-phone" class="control-label">备选电话：</label>
                  <div class="controls">
                    <input class="span3" id="tel" name="tel" size="30" type="text" value="<?php echo $result['tel'];?>" />
                    <span class="help-block">(为方便送餐员联系，请再留一个备用电话)</span> </div>
                </div>
                <!-- /control-group -->
              </fieldset>
              <input id="add_id" name="add_id" type="hidden" value="<?php echo $result['add_id'];?>" />
              <input id="method" name="method" type="hidden" value="saveCart" />
              <input id="remark" name="remark" type="hidden" value="" />
            </form>
          </div>
          <div class="span5 address-list">
            <ul class="checkout-address-list" id="checkout-address-list">
			<?php if($_SESSION['_user']['user_id']>0){?>
             <?php if(isset($_SESSION['_user'])){
	             	$res=mysql_query("select * from zy_address where is_delete=0 and user_id=".$_SESSION['_user']['user_id']);
	             	while($result=mysql_fetch_array($res)){
	             	?>
              <li class="<?php if($result['is_default']==1){echo "current";}?>">
                <input type="radio" class="radio" name="address[id]" <?php if($result['is_default']==1){echo "checked=\"checked\"";}?> value="<?php echo $result['add_id']?>" />
                <span class="address"><?php echo $result['address'];?></span> <br/>
                <span class="phone"><?php echo $result['phone'];?></span> <span class="tel"><?php echo $result['tel'];?></span></li>
              <li>
            <?php }?>
                <input type="radio" class="radio" name="address[id]" value="new" id="address-new"/>
                <span class="use-new">使用新地址</span> <span class="address hidden"></span> <span class="phone hidden"></span> <span class="phone-bk hidden"></span> </li>
           <?php }?>
            </ul>
			<?php }else{?></div>
		<div class="span5 address-list">
          <div class="quick-login">
      <h3>已有点一下账号？读取地址记录</h3>
	  <form action="check_out.php" method="post" id="quick-login-form" class="form-horizontal">
	  <div class="field_line" ><font color="red"><?php echo $error;?></font></div>
        <fieldset>
          <div class="control-group">
            <label for="username" class="control-label"><span class="required-mark">*</span>Email:</label>
            <div class="input">
              <input class="span3" id="mail" name="mail" size="30" type="text">
            </div>
          </div>
          <div class="control-group">
            <label for="password" class="control-label"><span class="required-mark">*</span>密码:</label>
            <div class="input">
              <input class="span3" id="password" name="password" type="password">
            </div>
          </div>
          <div class="control-group">
            <div class="input">
              <input type="submit" class="interactive small btn btn-yellow" data-loading-text="读取中..." id="quick-login-button" value="读取历史地址" name="submit"/>
            </div>
          </div>
        </fieldset>
		</form>
      </div><?php }?>
    </div>
   </div>
        <h2>点单备注（选填）</h2>
        <div class="row">
          <div class="span9 quick-notes" id="quick-remark"> <span>么零钱</span> <span>不要葱姜蒜</span> <span>不要筷子</span> <span>不吃辣</span> <span>辣一点</span> <span>多加米</span> <span>囧</span> <span>谢谢:)</span> </div>
          <div class="span9 notes">
            <textarea class="span8" name="remark" id="remark-text"></textarea>
          </div>
        </div>
        <div class="row" >
          <div class="confirm-button-wrapper" id="normal_payment_button" style="float:right; margin-right:25px;" >
              <button id="confirm-button-normal" type="submit" class="btn btn-yellow" data-loading-text="正在提交...">确认下单</button>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script type="text/javascript">
  function clickme(){
	  var s = document.getElementById("address").value;
	  var t =document.getElementById("phone").value;
	  var w=document.getElementById("tel").value;
	  var q=document.getElementById("total_price").innerHTML;
	  if(q>20){
	  if(w==""){
		  var str="总金额:"+q+"元\n"+"地址:"+s+"\n"+ "电话:"+t+"\n";
	  }else{
		  var str="总金额:"+q+"元\n"+"地址:"+s+"\n"+ "电话:"+t+"\n"+"备用电话:"+w+"\n";
	  }
			if(confirm(str)){
				form1.action="checkout_success.php";
				}else{
					return false;
				}
	  }
  }
  </script>
  <?php include (dirname(__FILE__)."/include/footer.php"); ?>
